<template>
  <div class="wrapper flex rel">
    <GSwiper :imgs="data.banners" auto>
      <template v-slot:img="{ img }">
        <div class="bannerItem">
          <div
            class="filter"
            :style="{ backgroundImage: 'url(' + img.imageUrl + ')' }"
          ></div>
          <a
            ><img
              class="banner_img"
              @click="songStore.setId(img.targetId)"
              :src="img.imageUrl"
              alt=""
          /></a>
        </div>
      </template>
    </GSwiper>

    <img class="download abs" src="@/assets/imgs/download.png" alt="" />
  </div>
  <div class="content sw flex">
    <div class="recommendList">
      <GBox title="热门推荐" target="/songList">
        <template #main>
          <div class="row flex between aligin_between recomm">
            <SimpleDisplayVue
              v-for="item in recommendList"
              :songList="item"
              @click="jump(item.id)"
            >
            </SimpleDisplayVue>
          </div>
        </template>
      </GBox>
      <div class="mb-40"></div>
      <GBox title="新碟上架" target="/newCD">
        <template #main>
          <div class="row">
            <div class="cd_container">
              <GSwiper :items="newCDs" :space="30" :num="5" nav>
                <template #item="{ item }">
                  <div class="cd_item">
                    <img class="CDCover" :src="item.coverUrl" alt="" />
                    <div class="alName">{{ item.albumName }}</div>
                    <p class="artistName">{{ item.artistName }}</p>
                  </div>
                </template>
              </GSwiper>
            </div>
          </div>
        </template>
      </GBox>
      <div class="mb-40"></div>

      <GBox title="榜单">
        <template #main>
          <div class="flex row">
            <ul
              class="recommend_rank"
              :class="{ clear_br: index == 2 }"
              v-for="(rank, index) in ranks"
            >
              <li class="rankHeader">
                <RankHeader :type="index"></RankHeader>
              </li>
              <li
                class="rank-Item"
                v-for="(song, index) in rank"
                @click="jumpSong(song.id)"
              >
                <a class="songName fs-12">
                  <i class="index" :class="{ active: index < 3 }">{{
                    index + 1
                  }}</i>
                  {{ song.name }}</a
                >
              </li>
              <li class="list-last rank-Item">
                <span class="all" @click="">查看全部</span>
              </li>
            </ul>
          </div>
        </template>
      </GBox>
    </div>
    <div class="asideColumn">
      <div class="login_area">
        <p class="fs-12">
          登录网易云音乐，可以享受无限收藏的乐趣，并且无限同步到手机
        </p>
        <div class="login_btn fs-12">用户登录</div>
      </div>
      <div class="g_asideBox">
        <div class="g_asideBox_header flex between">
          <div class="title fs-14">{{ '入驻歌手' }}</div>
          <div class="subtitle fs-12">{{ '查看全部 >' }}</div>
        </div>

        <div class="g_asideBox_main">
          <AsideList :list="list.singer" type="1"></AsideList>

          <div class="g_asideBox_header flex between">
            <div class="title fs-14">{{ '热门主播' }}</div>
          </div>
          <AsideList :list="list.streamer" type="2"></AsideList>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
export default {
  name: 'Recommend',
}
</script>

<script lang="ts" setup>
import { Songs } from '@/api/model/song'
import {
  reqBanners,
  reqNewCD,
  reqPlayList,
  reqRecommendSongList,
} from '@/api/recommend'
import { ref, reactive, onMounted } from 'vue'
import { bannerResponse } from '@/api/model/banner'
import GSwiper from '../../components/gSwiper/index.vue'
import GBox from '@/components/gBox/index.vue'
import SimpleDisplayVue from '@/components/SimpleDisplay.vue/index.vue'
import { songListItem, songLists } from '@/api/model/songList'
import { CDList } from '@/api/model/CD'
import RankHeader from './components/rankHeader.vue'
import list from '@/assets/mock/singer.json'
import AsideList from '@/components/AsideList/AsideList.vue'
import { RouteLocationNamedRaw, useRoute, useRouter } from 'vue-router'
import { useSongStore } from '@/stores/song'

let data = reactive<bannerResponse>({ banners: [] })
//let recommendSongList = reactive()
onMounted(() => {
  getBanners()
  getRecommendSongList(8)
  getNewCD()
  getRankDetail()
})

const songStore = useSongStore()
//获取轮播图
async function getBanners() {
  let { banners } = await reqBanners()
  data.banners = banners
}
//获取推荐歌单
let recommendList = ref<songLists>()
async function getRecommendSongList(limit: number) {
  const { result } = await reqRecommendSongList(limit)
  recommendList.value = result
}
const newCDs = ref<CDList>()
async function getNewCD() {
  const { products } = await reqNewCD(10)

  newCDs.value = products
}
//获取榜单数据

const ranks = ref<Array<Songs>>()
async function getRankDetail() {
  let limit = 10
  const risendata = await reqPlayList(19723756, limit)
  const latestdata = await reqPlayList(3779629, limit)
  const createdata = await reqPlayList(2884035, limit)

  ranks.value = [risendata.songs, latestdata.songs, createdata.songs]
  console.log(risendata, latestdata, createdata)
}
const router = useRouter()
const route = useRoute()

function jump(id: number) {
  router.push('/detail/songlist?songListId=' + id)
}
function jumpSong(id: number) {
  songStore.setId(id)
  router.push('/songDetail?id=' + id)
}
</script>

<style lang="less">
.recomm {
  height: 468px;
}
.wrapper {
  background-color: #ccc;
  .swiper-button-prev {
    left: 405px;
    color: #d2d1d1;
  }
  .swiper-button-next {
    color: #d2d1d1;
    right: 405px;
  }
}

.bannerItem {
  position: relative;
  height: 285px;
  .filter {
    height: 100%;
    background-size: 6000px;
    background-position: center center;
    filter: blur(40px);
  }
  .banner_img {
    position: absolute;
    top: 0;
    left: calc(50% - 490px);
    width: 730px;
    height: 285px;
  }
}

.g-box {
  margin-bottom: 20px;
}
.active {
  color: #ca0d0c;
}
.abs {
  position: absolute;
  left: calc(50% + 240px);

  z-index: 10;
}
.content {
  background: #ffffff;
}
.recommendList {
  width: 730px;
  border-left: 1px solid #d4d4d4;
  padding: 20px 20px 40px;
}
.asideColumn {
  border: 1px solid #d4d4d4;
  flex: 1;
}

.imgofSongList {
  height: 140px;
}
.textofSongList {
  font-size: 14px;
}

.row {
  padding-top: 20px;
  flex-wrap: wrap;
}
.cd_item {
  width: 100px;
}
.alName {
  font-size: 14px;
  padding-top: 5px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
.artistName {
  font-size: 12px;
  line-height: 20px;
}
.CDCover {
  width: 100px;
  box-shadow: 1px 1px 10px;
}
.cd_container {
  width: 684px;
  height: 184px;
  background-color: #f5f5f5;
  padding: 28px;
  border: 1px solid #d3d3d3;
}

.recommend_rank {
  width: 228px;
  height: 476px;
  background-color: #f4f4f4;
  & li:nth-child(even) {
    background-color: #e8e8e8;
  }
  border: 1px solid #d4d4d4;
  border-right: none;
}

.rank-Item {
  height: 32px;
  line-height: 32px;
  min-width: 0;
}
.songName {
  color: #000;
  display: inline-block;
  width: 60%;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
.rankHeader {
  width: 230px;
  height: 120px;
}
.index {
  font-size: 16px;
  width: 50px;
  padding-left: 20px;
  display: inline-block;
  text-align: center;
}

.list-last {
  text-align: right;
  font-size: 12px;
  padding-right: 30px;
  .all {
    cursor: pointer;
  }
}
.login_area {
  height: 120px;
  width: 250px;

  padding: 18px 20px;
  line-height: 22px;
  background-image: url('@/assets/imgs/4.png');
  border-bottom: 1px solid #d4d4d4;

  color: #666666;
}
.login_btn {
  height: 30px;
  width: 100px;
  margin: 10px auto;
  line-height: 30px;
  text-align: center;
  color: #fff;
  border-radius: 5px;
  background-image: url('@/assets/icon/btn.png');
}

.g_asideBox {
  width: 250px;
  padding: 18px;
}
a {
  cursor: pointer;
}
.g_asideBox_header {
  padding-bottom: 10px;
  border-bottom: 1px solid #d4d4d4;
  .title {
    font-weight: bold;
  }

  .subtitle {
    color: #666666;
  }
}
</style>
<style>
.simpleDisplay {
  width: 140px;
}
</style>
